#pragma once

/* 这个文件纯粹是给04compat用的 */

#include "tinystl/allocator.h"
#include "tinystl/vector.h"
#include "tinystl/string.h"
#include "tinystl/unordered_map.h"
#include "tinystl/unordered_set.h"

#if defined(BX_PLATFORM_ANDROID) && BX_PLATFORM_ANDROID
#include <sys/times.h>
#include <time.h>
#else

#if !BX_PLATFORM_PS5
#include <sys/timeb.h>
#endif
#include <time.h>

#endif

typedef tinystl::string bxstr;
typedef tinystl::string string;

template<typename T>
using bxvec = tinystl::vector<T>;
template<typename T>
using vector = bxvec<T>;

template<typename K, typename V>
using bxmap = tinystl::unordered_map<K, V>;
template<typename K, typename V>
using unordered_map = bxmap<K, V>;

template<typename K>
using bxset = tinystl::unordered_set<K>;
template<typename K>
using set = bxset<K>;

template<typename K,typename V>
using pair = tinystl::pair<K,V>;

namespace bx{

	inline bxstr getFileExt(const bxstr &path)
	{
		int it = path.find(".");
		if (it != bxstr::npos)
			return std::move(path.substr(it));
		return "";
	}
}

namespace bxutil
{
	bxstr getCurrentModulePath();
	bxstr getMainModulePath();

	tinystl::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len);
	bxvec<uint8_t> base64Decode(const char* encoded_string, size_t in_len) ;

	double getTimeInSecond();
	double getTimeInMiniSecond();
	double getTime();
    float getTimeFromStart();

	bxstr getTimeString(time_t t=0);

	bx::DefaultAllocator *getDefaultAllocator();

	template<typename T>
	using vector = tinystl::vector<T>;

	template<typename K, typename V>
	using map = tinystl::unordered_map<K, V>;

	template<typename K>
	using set = tinystl::unordered_set<K>;

	typedef vector<bxstr> strvec;

	bxstr getWorkPath();

	void splitString(const bxstr& s, tinystl::vector<bxstr>& v, const bxstr& c, bool trimEnd = true);
	tinystl::vector<bxstr> splitString(const bxstr& s,  const bxstr& c, bool trimEnd = true);

	void *alloc(size_t size);

	void free(void *ptr);

	using tinystl::string;

	string join(const vector<string>& vec, const string& sep);

	string replaceAll(const string& target, const string from, const string& to);

	bxstr normalizeFilePath(const char* _src, int32_t _num=0);

        bool isLatinNationalLetter(unsigned int ch);
}

template<typename K, typename V>
using bxpair = tinystl::pair<K, V>;

template<typename K, typename V>
bxpair<K, V> bxMakePair(const K &k, const V &v)
{
    return tinystl::make_pair(k, v);
}
